﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jitter.LinearMath;
using SharpDX;

namespace Engine
{
    public sealed class Conversion
    {
        /// <summary>
        /// JVector->Vector3
        /// </summary>
        /// <param name="vector"></param>
        /// <returns></returns>
        public static JVector ToJitterVector(Vector3 vector)
        {
            return new JVector(vector.X, vector.Y, vector.Z);
        }

        /// <summary>
        /// Vector3->JVector
        /// </summary>
        /// <param name="vector"></param>
        /// <returns></returns>
        public static Vector3 ToVector3(JVector vector)
        {
            return new Vector3((float)vector.X, (float)vector.Y, (float)vector.Z);
        }

        public static Matrix ToMatrix(JMatrix matrix)
        {
            Matrix TM = new Matrix();
            TM.M11 = (float)matrix.M11;
            TM.M12 = (float)matrix.M12;
            TM.M13 = (float)matrix.M13;
            //TM.M14 = 0.0f;
            TM.M21 = (float)matrix.M21;
            TM.M22 = (float)matrix.M22;
            TM.M23 = (float)matrix.M23;
            //TM.M24 = 0.0f;
            TM.M31 = (float)matrix.M31;
            TM.M32 = (float)matrix.M32;
            TM.M33 = (float)matrix.M33;
            //TM.M34 = 0.0f;
            //TM.M41 = 0.0f;
            //TM.M42 = 0.0f;
            //TM.M43 = 0.0f;
            TM.M44 = 1.0f;
            return TM;
        }

        public static Matrix ToMatrix(DMatrix matrix)
        {
            Matrix TM = new Matrix();
            TM.M11 = (float)matrix.M11;
            TM.M12 = (float)matrix.M12;
            TM.M13 = (float)matrix.M13;
            TM.M14 = (float)matrix.M14;
            TM.M21 = (float)matrix.M21;
            TM.M22 = (float)matrix.M22;
            TM.M23 = (float)matrix.M23;
            TM.M24 = (float)matrix.M24;
            TM.M31 = (float)matrix.M31;
            TM.M32 = (float)matrix.M32;
            TM.M33 = (float)matrix.M33;
            TM.M34 = (float)matrix.M34;
            TM.M41 = (float)matrix.M41;
            TM.M42 = (float)matrix.M42;
            TM.M43 = (float)matrix.M43;
            TM.M44 = (float)matrix.M44;
            return TM;
        }

        public static DMatrix ToDoubleMatrix(JMatrix matrix)
        {
            DMatrix TM = new DMatrix();
            TM.M11 = (float)matrix.M11;
            TM.M12 = (float)matrix.M12;
            TM.M13 = (float)matrix.M13;
            //TM.M14 = 0.0f;
            TM.M21 = (float)matrix.M21;
            TM.M22 = (float)matrix.M22;
            TM.M23 = (float)matrix.M23;
            //TM.M24 = 0.0f;
            TM.M31 = (float)matrix.M31;
            TM.M32 = (float)matrix.M32;
            TM.M33 = (float)matrix.M33;
            //TM.M34 = 0.0f;
            //TM.M41 = 0.0f;
            //TM.M42 = 0.0f;
            //TM.M43 = 0.0f;
            TM.M44 = 1.0f;
            return TM;
        }

        public static DMatrix ToDoubleMatrix(Matrix matrix)
        {
            DMatrix TM = new DMatrix();
            TM.M11 = matrix.M11;
            TM.M12 = matrix.M12;
            TM.M13 = matrix.M13;
            TM.M14 = matrix.M14;
            TM.M21 = matrix.M21;
            TM.M22 = matrix.M22;
            TM.M23 = matrix.M23;
            TM.M24 = matrix.M24;
            TM.M31 = matrix.M31;
            TM.M32 = matrix.M32;
            TM.M33 = matrix.M33;
            TM.M34 = matrix.M34;
            TM.M41 = matrix.M41;
            TM.M42 = matrix.M42;
            TM.M43 = matrix.M43;
            TM.M44 = matrix.M44;
            return TM;
        }

        public static JMatrix ToJitterMatrix(Matrix matrix)
        {
            JMatrix result;
            result.M11 = matrix.M11;
            result.M12 = matrix.M12;
            result.M13 = matrix.M13;
            result.M21 = matrix.M21;
            result.M22 = matrix.M22;
            result.M23 = matrix.M23;
            result.M31 = matrix.M31;
            result.M32 = matrix.M32;
            result.M33 = matrix.M33;
            return result;

        }

        public static JMatrix ToJitterMatrix(DMatrix matrix)
        {
            JMatrix result;
            result.M11 = matrix.M11;
            result.M12 = matrix.M12;
            result.M13 = matrix.M13;
            result.M21 = matrix.M21;
            result.M22 = matrix.M22;
            result.M23 = matrix.M23;
            result.M31 = matrix.M31;
            result.M32 = matrix.M32;
            result.M33 = matrix.M33;
            return result;

        }

        /// <summary>
        /// DVector3->JVector
        /// </summary>
        /// <param name="vector"></param>
        /// <returns></returns>
        public static JVector ToJitterVector(DVector3 vector)
        {
            return new JVector(vector.X, vector.Y, vector.Z);
        }

        /// <summary>
        /// DVector3->Vector3
        /// </summary>
        /// <param name="vector"></param>
        /// <returns></returns>
        public static Vector3 ToVector3(DVector3 vector)
        {
            return new Vector3((float)vector.X, (float)vector.Y, (float)vector.Z);
        }

        /// <summary>
        /// JVector->DVector3
        /// </summary>
        /// <param name="vector"></param>
        /// <returns></returns>
        public static DVector3 ToDoubleVector(JVector vector)
        {
            return new DVector3(vector.X, vector.Y, vector.Z);
        }

        /// <summary>
        /// Vector3->DVector3
        /// </summary>
        /// <param name="vector"></param>
        /// <returns></returns>
        public static DVector3 ToDoubleVector(Vector3 vector)
        {
            return new DVector3(vector.X, vector.Y, vector.Z);
        }

        /// <summary>
        /// Vector3->DVector3
        /// </summary>
        /// <param name="vector"></param>
        /// <returns></returns>
        public static DVector3 ToDoubleVector(Vector4 vector)
        {
            return new DVector3(vector.X, vector.Y, vector.Z);
        }

        /// <summary>
        /// Vector4->Vector3
        /// </summary>
        /// <param name="vector"></param>
        /// <returns></returns>
        public static Vector3 ToVector3(Vector4 vector)
        {
            return new Vector3(vector.X, vector.Y, vector.Z);
        }

        public static Vector4 ToVector4(DVector3 vector)
        {
            return new Vector4((float)vector.X, (float)vector.Y, (float)vector.Z, 0);
        }

        public static Vector4 ToVector4(Vector3 vector)
        {
            return new Vector4(vector.X, vector.Y, vector.Z, 0);
        }

        public static Vector4 ToVector4(Vector3 vector, float W)
        {
            return new Vector4(vector.X, vector.Y, vector.Z, W);
        }
    }
}
